import { Directive } from '@angular/core';
import { ValidatorFn, AbstractControl } from '@angular/forms';

@Directive({
    selector: '[appEmail]'
})
export class EmailValidDirective {

    constructor() { }

}

export function emailValidator(control: AbstractControl) {
    const _reg = /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/;
    if( control.value ){
        const _r = _reg.test(control.value);
        return !_r ? { "email": true } : null;
    }else{
        return null
    }
}

